package com.mall.shopping.services;
/*
 * @author 魏骏杰
 */

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import com.mall.shopping.utils.ExceptionProcessorUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@Service
@Component
public class IContentServiceImpl implements IContentService {
    @Autowired
    PanelContentMapper panelContentMapper;

    @Resource
    ContentConverter converter;

    @Override
    public NavListResponse queryNavList() {
        NavListResponse response = new NavListResponse();
        Example example = new Example(PanelContent.class);
        example.createCriteria().andBetween("id",55,61);
        try {
            List<PanelContent> list = panelContentMapper.selectByExample(example);
            List<PanelContentDto> panelContentDtos = converter.panelContents2Dto(list);
            response.setPanelContentDtos(panelContentDtos);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            log.error("IContentServiceImpl occur Exception :" + e);
            ExceptionProcessorUtils.wrapperHandlerException(response, e);
        }

        return response;
    }
}
